package com.longe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longe.common.Result;
import com.longe.dao.ChatRecordMapper;
import com.longe.entity.ChatRecord;
import com.longe.service.ChatRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author longe
 * @since 2020-05-23
 */
@Service
public class ChatRecordServiceImpl extends ServiceImpl<ChatRecordMapper, ChatRecord> implements ChatRecordService {

    @Override
    public Result<List<ChatRecord>> chatRecords(Integer userId, Integer friendId) {

        LambdaQueryWrapper<ChatRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatRecord::getUserId, userId).eq(ChatRecord::getFriendId, friendId);
        List<ChatRecord> list = this.list(queryWrapper);

        LambdaQueryWrapper<ChatRecord> query = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatRecord::getUserId, friendId).eq(ChatRecord::getFriendId, userId);
        List<ChatRecord> list2 = this.list(query);

        list.addAll(list2);
        return new Result<>(true, "SUCCESS", list);
    }
}
